<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Inc. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 * 
 * Official Website 
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/documents
 */

class appRain_Base_Modules_PageManager extends Development_Callbacks
{
	/**
	 * Base function to call Page Section
	 * 
	 * @param $type String
	 * @return Object
	 */
	public function PageManager()
    {
        $this->setFetchtype('PageManager');
        return $this;
    }
    
	/**
	 * Get Page data
	 */
	public function getData($pageName = NULL, $fieldName = NULL)
	{
		$status_id = App::getUserStatusId();
		if(isset($pageName))
		{
			$data = App::Load("Model/Page")->find("name='{$pageName}' AND fkey=$status_id");
			return isset($data[$fieldName]) ? $data[$fieldName] : $data;
		}
		else
		{
			return App::Load("Model/Page")->findAll("fkey=$status_id");
		}
	}
	
    /**
     * To process get static page information
     * 
     * @param $flag String
     * @param $flag2 String
     */
    public function pages( $flag = "all", $flag2 = NULL)
    {

        $status_id = App::getUserStatusId();

        switch( $flag )
        {
            case "name_only":

                                $page_arr  =  App::Load("Model/Page")->findAll("fkey=$status_id");
                                $data = array();
                                foreach( $page_arr['data'] as $key => $val )$data[$val['id']] = $val['name'];
                                return $data;
                                break;
            case "title_only":
                                $page_arr  =  App::Load("Model/Page")->findAll("fkey=$status_id");
                                $data = array();
                                foreach( $page_arr['data'] as $key => $val )$data[$val['id']] = $val['title'];
                                return $data;
                                break;
            case "by_name"   :
                                return  App::Load("Model/Page")->findAll("name='$flag2' AND fkey=$status_id");
                                break;
            case "all":
                                return  App::Load("Model/Page")->findAll("fkey=$status_id ORDER BY title ASC");
                                break;
            default:
                                return App::Load("Model/Page")->findById("$flag");
                                break;
        }		
    }    
} 
